﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string.h>
#include <math.h>
#include <unordered_map>
using namespace std;

struct ListNode {
    int val;
    ListNode* next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode* next) : val(x), next(next) {}
};

class Solution {
public:
    ListNode* removeZeroSumSublists(ListNode* head) {
        unordered_map<int, ListNode*> mp;
        ListNode* phead = new ListNode(0);
        phead->next = head;
        ListNode* tmp = phead;
        int sum = 0;
        while (tmp)
        {
            sum += tmp->val;
            mp[sum] = tmp;
            tmp = tmp->next;
        }
        sum = 0;
        tmp = phead;
        while (phead)
        {
            sum += phead->val;
            phead->next = mp[sum]->next;
            phead = phead->next;
        }

        return tmp->next;

    }
};

int main()
{
    return 0;
}